Skip to content

Revert "fix: Fix airplane mode tips display logic"#492

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
ut003640:master
Feb 4, 2026
Merged

Revert "fix: Fix airplane mode tips display logic"#492
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
ut003640:master

Conversation

@ut003640
Copy link
Copy Markdown
Contributor

@ut003640 ut003640 commented Feb 4, 2026

This reverts commit 95539e9.

Summary by Sourcery

Revert the previous change to airplane mode tips handling and restore the original behavior.

Bug Fixes:

  • Restore the original airplane mode support check logic by inlining the wireless device detection into supportAirplaneMode and removing the separate supportWireless helper.

Enhancements:

  • Simplify airplane mode tips visibility to depend only on airplane mode state rather than wireless support.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Feb 4, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR reverts a previous change to airplane mode tips logic by inlining the wireless-support check into supportAirplaneMode() and simplifying the UI visibility condition so that airplane mode tips depend only on airplane mode state, not on detected wireless devices.

Class diagram for airplane mode support and tips logic

classDiagram
  class NetManagerThreadPrivate {
    - bool m_airplaneModeEnabled
    + bool AirplaneModeEnabled() const
    + bool supportAirplaneMode() const
    + void setEnabled(bool enabled)
    + void setAutoScanInterval(int ms)
    + void setAutoScanEnabled(bool enabled)
  }

  class NetManagerPrivate {
    - bool m_airplaneMode
    - NetManagerThreadPrivate* m_managerThread
    + void updateAirplaneMode(bool enabled)
    + void updateItemVisible(QString itemId, bool visible)
  }

  NetManagerPrivate --> NetManagerThreadPrivate : uses

  note for NetManagerThreadPrivate "supportWireless method removed; its wifi detection logic is now in supportAirplaneMode"
Loading

File-Level Changes

Change Details Files
Revert the reusable wireless support helper and restore direct device scanning inside supportAirplaneMode().
  • Remove the supportWireless() method declaration from the thread private header.
  • Remove the supportWireless() method definition that iterated over NetworkManager devices.
  • Inline the wireless device scan logic directly into supportAirplaneMode(), returning true if a managed Wi-Fi device is present, otherwise false.
net-view/operation/private/netmanagerthreadprivate.h
net-view/operation/private/netmanagerthreadprivate.cpp
Simplify airplane mode tips visibility to depend solely on airplane mode being enabled.
  • Change updateAirplaneMode() to call updateItemVisible("NetAirplaneModeTipsItem", enabled) instead of gating on supportWireless().
  • Leave other related visibility updates (wireless/wired disabled items) unchanged when airplane mode is enabled.
net-view/operation/netmanager.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

这段代码的 diff 主要进行了两个方面的修改:

  1. 删除了 NetManagerThreadPrivate::supportWireless() 函数。
  2. 将该函数的逻辑直接内联到 NetManagerThreadPrivate::supportAirplaneMode() 中,并修改了 NetManagerPrivate::updateAirplaneMode 中调用该逻辑的地方。

以下是从语法逻辑、代码质量、代码性能和代码安全四个方面的详细审查意见:

1. 语法逻辑

  • 逻辑正确性:代码逻辑是正确的。修改后的 supportAirplaneMode 函数在检查完其他条件后,直接遍历网络设备判断是否存在受管理的 WiFi 设备,这与原 supportWireless 的逻辑一致。
  • 调用一致性:在 netmanager.cpp 中,updateAirplaneMode 函数原本调用 updateItemVisible("NetAirplaneModeTipsItem", enabled && m_managerThread->supportWireless());,现在改为 updateItemVisible("NetAirplaneModeTipsItem", enabled);
    • 潜在问题:这里需要仔细确认业务逻辑。原来的逻辑是:只有当开启飞行模式系统支持无线时,才显示飞行模式提示项。现在的逻辑是:只要开启飞行模式就显示提示项,不再检查是否支持无线。
    • 如果这是一个纯有线网络环境(无 WiFi 卡),开启飞行模式通常没有实际意义(因为飞行模式主要针对无线信号)。原来的逻辑在这种情况下不显示提示是合理的。修改后,即使没有无线网卡,开启飞行模式也会显示提示,这可能会导致用户困惑或 UI 显示异常。建议确认是否真的需要移除对无线支持的检查。

2. 代码质量

  • 代码重复:这是一个典型的代码重复问题。原本 supportWireless 是一个独立的函数,可能被多处复用(虽然 diff 中只显示了在 supportAirplaneMode 中的使用)。现在将这段逻辑直接写在 supportAirplaneMode 内部,如果未来其他地方(比如 UI 刷新、状态判断)还需要判断是否有无线网卡,开发者就不得不再写一遍这段遍历设备的代码,或者重新提取函数。这降低了代码的可维护性。
  • 命名与封装supportWireless 作为一个独立的函数,语义清晰("是否支持无线")。将其内联后,这个语义在 supportAirplaneMode 中变得隐晦。虽然飞行模式依赖于无线支持,但"支持无线"本身是一个独立的状态属性。

3. 代码性能

  • 性能影响
    • NetworkManager::networkInterfaces() 是一个 DBus 调用,通常涉及到 IPC(进程间通信),开销相对较大。
    • 原代码中,如果 supportAirplaneMode 前面的检查(如蓝牙支持等)已经返回 true,则不会调用 supportWireless,从而节省了一次 DBus 调用。
    • 新代码将遍历逻辑放在了 supportAirplaneMode 的末尾,逻辑流上没有增加额外的调用开销(前提是 netmanager.cpp 中不再调用 supportWireless)。
    • 注意:如果在 updateAirplaneMode 中原本的调用 m_managerThread->supportWireless() 被移除,而在 supportAirplaneMode 内部又实现了相同逻辑,那么在 updateAirplaneMode 被调用时,性能是持平的。但如果 updateAirplaneMode 的逻辑改为不再检查无线支持(如前文所述),那么在 netmanager.cpp 这一边确实是省了一次 DBus 调用,但代价是逻辑可能不严谨。

4. 代码安全

  • 空指针与异常:代码中使用了 NetworkManager::networkInterfaces(),返回的是设备列表。遍历列表本身是安全的,但需确保 NetworkManager 库在调用时已初始化且 DBus 连接正常。原代码和新代码在这方面风险一致。
  • 线程安全NetManagerThreadPrivate 类名暗示其运行在特定线程中。遍历网络设备的操作通常在主线程或工作线程中执行,需确保 NetworkManager 的调用是线程安全的。原代码和新代码在这方面风险一致。

改进建议

  1. 恢复 supportWireless 函数
    建议保留 supportWireless 函数,或者将其重命名为更通用的名称(如 hasManagedWifiDevice),并在 supportAirplaneMode 中继续调用它。这样可以避免代码重复,保持逻辑清晰。

    // 在 netmanagerthreadprivate.h 中声明
    bool hasManagedWifiDevice() const;
    
    // 在 netmanagerthreadprivate.cpp 中实现
    bool NetManagerThreadPrivate::hasManagedWifiDevice() const
    {
        NetworkManager::Device::List devices = NetworkManager::networkInterfaces();
        for (NetworkManager::Device::Ptr device : devices) {
            if (device->type() == NetworkManager::Device::Type::Wifi && device->managed())
                return true;
        }
        return false;
    }
    
    // 在 supportAirplaneMode 中调用
    bool NetManagerThreadPrivate::supportAirplaneMode() const
    {
        // ... 其他检查 ...
        return hasManagedWifiDevice();
    }
  2. 审查 netmanager.cpp 中的逻辑变更
    强烈建议回滚 netmanager.cpp 中的这一行修改:

    // 当前修改
    updateItemVisible("NetAirplaneModeTipsItem", enabled);
    
    // 建议恢复为
    updateItemVisible("NetAirplaneModeTipsItem", enabled && m_managerThread->hasManagedWifiDevice());

    理由:在没有无线网卡的机器上显示"飞行模式已开启"的提示通常是不合理的,保留对无线支持的检查可以避免此类 UI 逻辑错误。

  3. 性能优化(可选)
    由于 NetworkManager::networkInterfaces() 调用开销较大,如果 supportAirplaneMode 或 UI 刷新被频繁调用,建议在 NetManagerThreadPrivate 类中增加一个成员变量(如 m_hasWifi),并在设备列表变化时(监听 NetworkManager 的设备添加/移除信号)更新该变量。这样判断支持无线时只需读取布尔变量,无需每次都进行 DBus 查询。

    // 头文件
    mutable bool m_hasWifi = false; // 使用 mutable 允许在 const 函数中缓存
    
    // 实现
    bool NetManagerThreadPrivate::hasManagedWifiDevice() const
    {
        // 如果已有缓存且未过期,直接返回
        // 注意:需要配合设备变化信号来重置 m_hasWifi
        return m_hasWifi;
    }

    注:此优化需要配合信号槽机制维护缓存状态,增加了复杂度,仅在性能分析证明此处为瓶颈时才实施。

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: caixr23, ut003640

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ut003640
Copy link
Copy Markdown
Contributor Author

ut003640 commented Feb 4, 2026

/forcemerge

@deepin-bot
Copy link
Copy Markdown
Contributor

deepin-bot bot commented Feb 4, 2026

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit d3aee5c into linuxdeepin:master Feb 4, 2026
16 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants